﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Data.SqlClient;
using System.Xml;
using Manager;
using System.Web.Script.Services;
using System.Collections;

/// <summary>
/// Summary description for ServiceProducts
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class ServiceProducts : System.Web.Services.WebService {

    public ServiceProducts () {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    public string HelloWorld() {
        return "Hello World";
    }

    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public DataSet Products(int pageCurrent)
    {
        ArrayList list = new ArrayList();
        DbManager db = new DbManager();
        DataTable tb_new = new DataTable();
        //string[] table = { "Products" };
        //SqlParameter[] param1 = { 
        //        new SqlParameter("p_Status","0")
        //    };
        //DataTable tb_product = db.tableSearch(1, 12, table, param1); //db.tableSearch(pageCurrent, 12, table, param1);

        //tb_new.Columns.Add("ID", typeof(string));
        //tb_new.Columns.Add("Name", typeof(string));
        //tb_new.Columns.Add("Image", typeof(string));
        //tb_new.Columns.Add("Reduced_price", typeof(string));
        //tb_new.Columns.Add("Real_price", typeof(string));

        //foreach (DataRow row in tb_product.Rows)
        //{
        //    XmlDocument doc = new XmlDocument();
        //    doc.LoadXml(row["p_Image"].ToString());
        //    string img = doc.SelectNodes("/images/image[1]")[0].FirstChild.InnerText;
        //    doc.LoadXml(row["p_Price"].ToString());
        //    string rd_price = doc.SelectNodes("/price")[0].FirstChild.InnerText;
        //    string rl_price = doc.SelectNodes("/price")[0].LastChild.InnerText;
        //    tb_new.Rows.Add(row["p_ID"].ToString(), row["p_Name"].ToString(), img, rl_price, rd_price);
        //}
        //tb_new.TableName = "Products";
        DataSet ds = new DataSet();
        return ds;
    }
    
}
